<template>
  <div>
    <!-- 搜索 -->
    <!-- 索赔附加项目维护  车厂 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="false" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi" :datakey="'rows'" :onColumnsChange="columns => (this.columns = columns)" :is-select-column="false">
      <template slot="controls" slot-scope="props">
            <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="actions.visible" :title="actions.title" width="450px" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ItemsForm @close="close" :formData="formData" :type="actions.type"></ItemsForm>
    </BaseDialog>
  </div>
</template>
<script>
import { getListByPage } from '@/api/claim/factory/AdditionalWarrantyItems';
import { dictionary } from '@/utils/dictMixin';
import ItemsForm from './ItemsForm.vue';
export default {
  mixins: [dictionary],
  components: { ItemsForm },
  data() {
    return {
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      actions: { type: '', title: '', visible: false, data: null },
      formData: {}
    };
  },
  methods: {
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '附加项目代码',
          fieldName: 'labourCode',
          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '附加项目名称',
          fieldName: 'labourName',
          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否有效',
          fieldName: 'isValid',
          placeholder: '请选择...',
          initialValue: '',
          itemList: this.createDictList(1004)
        }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          minWidth: '100',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editFun(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        { title: '附加项目代码', dataIndex: 'labourCode', sorter: true },
        { title: '附加项目名称', dataIndex: 'labourName', sorter: true },
        {title: '附加项目费用', dataIndex: 'labourPrice', sorter: true},
        {title: '是否有效', dataIndex: 'isValIdName', sorter: true},
      ];
    },
    async editFun(row){
        this.formData = row;
        this.actions = { type: 'edit', visible: true, title: '编辑附加项目' };
    },
    add(){
      this.actions = { type: 'add', title: '新增附加项目', visible: true };
    },
    close(val){
      this.actions.visible = val;
      this.fetchParams = Object.assign({}, this.fetchParams);
    }
  }
};
</script>

<style lang="less" scoped></style>
